package entity

import (
	"context"
	"time"

	"github.com/LyricTian/gin-admin/v7/internal/app/schema"
	"github.com/LyricTian/gin-admin/v7/pkg/util/structure"
	"github.com/jinzhu/gorm"
)

// GetVideoDB 获取video存储
func GetVideoDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
	return GetDBWithModel(ctx, defDB, new(Video))
}

// SchemaVideo video对象
type SchemaVideo schema.Video

// ToVideo 转换为video实体
func (a SchemaVideo) ToVideo() *Video {
	item := new(Video)
	structure.Copy(a, item)
	return item
}

// Video video实体
type Video struct {
	ID          string     `gorm:"column:id;primary_key;size:36;"`
	Name        string     `gorm:"column:name;size:120;"`         // 标题
	Url         string     `gorm:"column:url;size:255;"`          // 播放链接
	Type        int        `gorm:"column:type;size:11;"`          // 类型(1:公开 2:私有)
	ContentType int        `gorm:"column:content_type;size:11;"`  // 内容类型(1:语音 2:视频)
	Content     string     `gorm:"column:content;size:1024;"`     // 内容
	TimeZone    int        `gorm:"column:time_zone;size:11;"`     // 时区
	Duration    int        `gorm:"column:duration;size:11;"`      // 时长
	Memo        string     `gorm:"size:516;column:memo;"`         // 简介
	Status      int        `gorm:"column:status;size:11;"`        // 状态(1:启用 2:停用)
	Author      string     `gorm:"size:36;index;column:author;"`  // 作者
	Creator     string     `gorm:"size:36;index;column:creator;"` // 创建者
	CreatedAt   time.Time  `gorm:"column:created_at;index;"`
	UpdatedAt   time.Time  `gorm:"column:updated_at;index;"`
	DeletedAt   *time.Time `gorm:"column:deleted_at;index;"`
}

// ToSchemaVideo 转换为video对象
func (a Video) ToSchemaVideo() *schema.Video {
	item := new(schema.Video)
	structure.Copy(a, item)
	return item
}

// Videos video列表
type Videos []*Video

// ToSchemaVideos 转换为video对象列表
func (a Videos) ToSchemaVideos() []*schema.Video {
	list := make([]*schema.Video, len(a))
	for i, item := range a {
		list[i] = item.ToSchemaVideo()
	}
	return list
}
